from time import sleep
from appium.webdriver.common.appiumby import AppiumBy
from common.base_page import BasePage
import random


class CreateCompetition(BasePage):
    # 模拟炒股
    imitate_loc = (AppiumBy.XPATH, '//android.widget.ImageView[@bounds="[411,1491][489,1569]"]')
    # 比赛
    competition_loc = (AppiumBy.XPATH, '//android.widget.TextView[@text=" 比赛 "]')
    # 创建比赛
    createCompetition_loc = (AppiumBy.ID, 'com.jhss.youguu:id/iv_create_match')
    # 输入比赛名称
    competitionName_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_match_name')
    # 比赛简介
    introduce_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_match_introduce')
    # 点击初始资金
    fund_loc = (AppiumBy.ID, 'com.jhss.youguu:id/tv_initial_fund')
    # 选择初始资金
    initialFunding_loc = (AppiumBy.ID, 'com.jhss.youguu:id/rl_mif_item')
    # 点击创建
    create_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_right_text')
    # 点击确定
    determine = (AppiumBy.ID, 'com.jhss.youguu:id/btn_common_confirm')
    # 点击取消
    cancellation = (AppiumBy.ID, 'com.jhss.youguu:id/btn_common_cancel')
    # 点击我创建的
    iCreated_loc = (AppiumBy.XPATH, '//android.support.v7.app.ActionBar.Tab['
                                    '@content-desc="我创建的"]/android.widget.TextView')
    # 获取比赛名称文本
    name_loc = (AppiumBy.ID, 'com.jhss.youguu:id/tv_match_name')

    # 点击发现
    find_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_desktop_discovery')
    # 点击头像
    head_loc = (AppiumBy.ID, 'com.jhss.youguu:id/head_pic')
    # 用户信息
    user_loc = (AppiumBy.ID, 'com.jhss.youguu:id/iv_user_avatar')
    # 动态
    trends_loc = (AppiumBy.ID, '//android.support.v7.app.ActionBar.Tab[@content-desc="动态"]/android.widget.TextView')
    # 获取比赛名称
    name1_loc = (AppiumBy.XPATH, '//android.widget.TextView[@text="2104AAAAA"]')

    # 创建操作
    def create(self, name, brief):
        # 模拟炒股
        self.click_ele(self.imitate_loc)
        # 比赛
        self.click_ele(self.competition_loc)
        # 创建比赛
        self.click_ele(self.createCompetition_loc)
        # 输入比赛名称
        self.send_keys(self.competitionName_loc, name)
        # 比赛简介
        self.send_keys(self.introduce_loc, brief)
        # 点击初始资金
        self.click_ele(self.fund_loc)
        # 选择初始资金
        self.click_ele(self.initialFunding_loc)
        sleep(5)
        # 点击创建
        self.click_ele(self.create_loc)
        # 点击确定
        self.click_ele(self.determine)
        # 点击取消
        self.click_ele(self.cancellation)
        # 点击我创建的
        self.click_ele(self.iCreated_loc)
        sleep(2)
        # 点击发现
        self.click_ele(self.find_loc)
        # 点击头像
        self.click_ele(self.head_loc)
        # 点击信息
        self.click_ele(self.user_loc)
        # 点击动态
        self.click_ele(self.trends_loc)
        sleep(4)


